﻿/******************************************************************************
 * Copyright (C) 671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef GAME_GAMEAPPLICATION_H_
#define GAME_GAMEAPPLICATION_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <string>
#include <NodeCpp/Event.h>
#include <NodeCpp/Util/Application.h>
#include <NodeCpp/Util/XmlConfiguration.h>
#include <NodeCpp/Net/TcpServer.h>
#include "Shared/Typedef.h"
using NodeCpp::Event;
using NodeCpp::Util::Application;
using NodeCpp::Util::OptionSet;
using NodeCpp::Util::XmlConfiguration;
using NodeCpp::Net::TcpServer;

class GameApplication : public Application
{
public:
    GameApplication(void);
    virtual ~GameApplication(void);

    virtual const Configuration& conf(void) const { return Conf_; }

protected:
    virtual void OnDefineOptions(OptionSet& _Options);
    virtual int OnOption(const std::string& _Name, const std::string& _Arg);
    virtual int OnInitialize(void);
    virtual void OnSignal(int _Signal);
    virtual int Main(std::vector<std::string>& _UnknownArgs);
    virtual void OnUninitialize(void);

private:
    bool _StartDB(void);

    std::string ConfPath_;
    XmlConfiguration Conf_;
    DBType LoginDB_;
    DBType CharaDB_;
    DBType WorldDB_;
    TcpServer NetServer_;
    volatile bool Running_;
    Event StopExit_;
};

#endif // GAME_GAMEAPPLICATION_H_
